package com.dy.wind.utils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author Hasee
 * @Description TODO
 * @date 2022/3/17-11:56
 */
public class CutPicUtil {
    /**
     * @Description: 屏幕截图 
     * @Param: [imageName, path, imgType, screenRectangle] 
     * @return: void 
     * @Author: wind
     * @Date: 2022-03-17 11:57:26-
     **/
    public static void cutPic(String imageName,String path,String imgType,Rectangle screenRectangle) throws AWTException, IOException {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle rectangleScreen = new Rectangle(screenSize);
        Robot robot = new Robot();
        File file = new File(path);
        if (!file.isDirectory()){
            file.mkdir();
        }
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        ImageIO.write(image,imgType, new File(path+imageName+"."+imgType));
    }
}
